package common.locale;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Named;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Created by Gerardo on 1/12/14.
 */
public class LocaleModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(Locale.class).toInstance(Locale.getDefault());
    }

    @Provides
    @Named("Greeting")
    String getGreeting(final Locale locale) {
        final ResourceBundle bundle = ResourceBundle.getBundle("ResourceBundle", locale);
        return bundle.getString("Greeting");
    }

    @Provides
    NumberFormat getNumberFormat(final Locale locale) {
        return NumberFormat.getInstance(locale);
    }

    @Provides
    @Named("Currency")
        //TODO Currency Annotation
    NumberFormat getCurrencyFormat(final Locale locale) {
        return NumberFormat.getCurrencyInstance(locale);
    }

    @Provides
    @Named("Time")
        //TODO Time Annotation
    DateFormat getTimeFormat(final Locale locale) {
        return DateFormat.getTimeInstance(DateFormat.FULL, locale);
    }

    @Provides
    @Named("DateTime")
        //TODO DateTime Annotation
    DateFormat getDateTimeFormat(final Locale locale) {
        return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, locale);
    }
}
